<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="计划id" prop="scheduleId">
      <el-input v-model="dataForm.scheduleId" placeholder="计划id"></el-input>
    </el-form-item>
    <el-form-item label="完成情况总结" prop="summaryContent">
      <el-input v-model="dataForm.summaryContent" placeholder="完成情况总结"></el-input>
    </el-form-item>
    <el-form-item label="未完成原因总结" prop="notRealizeReason">
      <el-input v-model="dataForm.notRealizeReason" placeholder="未完成原因总结"></el-input>
    </el-form-item>
    <el-form-item label="改进方案" prop="improvementSolution">
      <el-input v-model="dataForm.improvementSolution" placeholder="改进方案"></el-input>
    </el-form-item>
    <el-form-item label="评分" prop="grade">
      <el-input v-model="dataForm.grade" placeholder="评分"></el-input>
    </el-form-item>
    <el-form-item label="总结分类（1-日总结；2-周总结；3-月总结）" prop="type">
      <el-input v-model="dataForm.type" placeholder="总结分类（1-日总结；2-周总结；3-月总结）"></el-input>
    </el-form-item>
    <el-form-item label="总结用户id" prop="createUserId">
      <el-input v-model="dataForm.createUserId" placeholder="总结用户id"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          scheduleId: '',
          summaryContent: '',
          notRealizeReason: '',
          improvementSolution: '',
          grade: '',
          type: '',
          createUserId: '',
          createTime: ''
        },
        dataRule: {
          scheduleId: [
            { required: true, message: '计划id不能为空', trigger: 'blur' }
          ],
          summaryContent: [
            { required: true, message: '完成情况总结不能为空', trigger: 'blur' }
          ],
          notRealizeReason: [
            { required: true, message: '未完成原因总结不能为空', trigger: 'blur' }
          ],
          improvementSolution: [
            { required: true, message: '改进方案不能为空', trigger: 'blur' }
          ],
          grade: [
            { required: true, message: '评分不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '总结分类（1-日总结；2-周总结；3-月总结）不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '总结用户id不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/avanotes/schedulesummary/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.scheduleId = data.scheduleSummary.scheduleId
                this.dataForm.summaryContent = data.scheduleSummary.summaryContent
                this.dataForm.notRealizeReason = data.scheduleSummary.notRealizeReason
                this.dataForm.improvementSolution = data.scheduleSummary.improvementSolution
                this.dataForm.grade = data.scheduleSummary.grade
                this.dataForm.type = data.scheduleSummary.type
                this.dataForm.createUserId = data.scheduleSummary.createUserId
                this.dataForm.createTime = data.scheduleSummary.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/avanotes/schedulesummary/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'scheduleId': this.dataForm.scheduleId,
                'summaryContent': this.dataForm.summaryContent,
                'notRealizeReason': this.dataForm.notRealizeReason,
                'improvementSolution': this.dataForm.improvementSolution,
                'grade': this.dataForm.grade,
                'type': this.dataForm.type,
                'createUserId': this.dataForm.createUserId,
                'createTime': this.dataForm.createTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
